package com.bm.specialvehiclefordispatcher.views;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bm.specialvehiclefordispatcher.R;

/**
 * @Copyright Copyright 2014 蓝色互动. All rights reserved.
 * 
 * @author GuoHao
 */
public class CommonNavigationBar extends LinearLayout {

	Context context;
	/**
	 * 标题
	 */
	TextView title;

	/**
	 * 返回
	 */
	LinearLayout back;

	LinearLayout right;

	TextView rigth_text, tv_right_action;

	ImageView back_image;

	ImageView mine_image;

	public CommonNavigationBar(Context context) {
		super(context);
		this.context = context;
		init();
	}

	public CommonNavigationBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		init();
	}

	public CommonNavigationBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
		init();
	}

	private void init() {
		LayoutInflater.from(context).inflate(R.layout.navigationbar, this);
		title = (TextView) findViewById(R.id.title);
		back = (LinearLayout) findViewById(R.id.back);
		right = (LinearLayout) findViewById(R.id.right_lin);
		rigth_text = (TextView) findViewById(R.id.right_text);
		back_image = (ImageView) findViewById(R.id.back_image);
		mine_image = (ImageView) findViewById(R.id.mine_image);
		tv_right_action = (TextView) findViewById(R.id.tv_right_action);
	}

	/**
	 * @author GuoHao
	 * @Package com.bm.talonmobileinternal.views
	 * @param listener
	 * @return void
	 * @throws 返回
	 */
	public void setListener(OnClickListener listener) {
		if (listener != null) {
			back.setVisibility(View.VISIBLE);
			back.setOnClickListener(listener);
		} else {
			back.setVisibility(View.VISIBLE);
			back.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					((Activity) context).finish();
				}
			});
		}
	}

	/**
	 * @author GuoHao
	 * @Package com.bm.talonmobileinternal.views
	 * @param title_txt
	 * @return void
	 * @throws
	 * @Date 设置标题传string
	 */
	@SuppressLint("ResourceAsColor")
	public void setTitle(String title_txt) {
		title.setText(title_txt);
	}

	/**
	 * @author GuoHao
	 * @Package com.bm.talonmobileinternal.views
	 * @param txt
	 * @return void
	 * @throws
	 * @Date 设置标题传int
	 */
	@SuppressLint("ResourceAsColor")
	public void setTitle(int txt) {
		title.setText(txt);
	}

	/**
	 * @author GuoHao
	 * @Package com.bm.specialvehicle.views
	 * @param string
	 * @param clickListener
	 * @return void
	 * @throws
	 * @Date 2015年8月13日 下午2:04:46 显示右边的按钮
	 */
	public void setRightBtnAndText(String string, OnClickListener clickListener) {
		right.setVisibility(View.VISIBLE);
		if (clickListener != null) {
			right.setOnClickListener(clickListener);
		}
		rigth_text.setText(string);
	}
	
	public void showRightActionAndText(String string, OnClickListener clickListener) {
		tv_right_action.setVisibility(View.VISIBLE);
		if (clickListener != null) {
			tv_right_action.setOnClickListener(clickListener);
		}
		tv_right_action.setText(string);
	}
	
	public void hideRightAction(){
		tv_right_action.setVisibility(View.GONE);
	}

	/**
	 * @author GuoHao
	 * @Package com.bm.specialvehicle.views
	 * @return void
	 * @throws
	 * @Date 2015年8月13日 下午2:05:44 隐藏右边按钮
	 */
	public void hideRightBtn() {
		right.setVisibility(View.GONE);
	}

	public void showLeftMineBtn(OnClickListener clickListener) {
		back.setVisibility(View.VISIBLE);
		mine_image.setVisibility(View.VISIBLE);
		back_image.setVisibility(View.GONE);
		back.setOnClickListener(clickListener);
	}

	public void hideLeftMineBtn() {
		mine_image.setVisibility(View.GONE);
		back_image.setVisibility(View.VISIBLE);
	}

}
